﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace Waker.APIs.NVR
{
    public static class NVRHelper
    {
        #region 基础数据
        public struct NET_DVR_JPEGPARA
        {
            /// <summary>
            /// wPicSize 图片尺寸：0-CIF，1-QCIF，2-D1，3-UXGA(1600x1200)，4-SVGA(800x600)，5-HD720p(1280x720)，6-VGA，7-XVGA，8-HD900p，9-HD1080，10-2560*1920，11-1600*304，12-2048*1536，13-2448*2048，14-2448*1200，15-2448*800，16-XGA(1024*768)，17-SXGA(1280*1024)，18-WD1(960*576/960*480),19-1080i 
            /// </summary>
            ushort wPicSize;
            /// <summary>
            /// wPicQuality 图片质量系数：0-最好，1-较好，2-一般 
            /// </summary>
            ushort wPicQuality;
        }
        //      public   struct NET_DVR_DEVICEINFO_V30{
        //          /// <summary>
        //          /// 序列号 长度48
        //          /// </summary>
        //  byte[]     sSerialNumber  ;
        //  byte     byAlarmInPortNum;
        //  byte     byAlarmOutPortNum;
        //  byte     byDiskNum;
        //  byte     byDVRType;
        //  byte     byChanNum;
        //  byte     byStartChan;
        //  byte     byAudioChanNum;
        //  byte     byIPChanNum;
        //  byte     byZeroChanNum;
        //  byte     byMainProto;
        //  byte     bySubProto;
        //  byte     bySupport;
        //  byte     bySupport1;
        //  byte     byRes1;
        //  ushort     wDevType;
        //  byte[]     byRes2[16] ;
        //}
        #endregion
        /// <summary>
        /// 初始化SDK，调用其他SDK函数的前提。
        /// </summary>
        /// <returns></returns>
        [DllImport(@"APIs\NVR\HCNetSDK.dll", EntryPoint = "NET_DVR_Init", CharSet = CharSet.Ansi)]
        public static extern bool NET_DVR_Init();
        /// <summary>
        /// 释放SDK资源，在结束之前最后调用。
        /// </summary>
        /// <returns></returns>
        [DllImport(@"APIs\NVR\HCNetSDK.dll", EntryPoint = "NET_DVR_Cleanup", CharSet = CharSet.Ansi)]
        public static extern bool NET_DVR_Cleanup();
        [DllImport(@"APIs\NVR\HCNetSDK.dll", EntryPoint = "NET_DVR_GetLastError", CharSet = CharSet.Ansi)]
        public static extern uint NET_DVR_GetLastError();
        [DllImport(@"APIs\NVR\HCNetSDK.dll", EntryPoint = "NET_DVR_GetErrorMsg", CharSet = CharSet.Ansi)]
        public static extern string NET_DVR_GetErrorMsg(out int pErrorNo);
        //  [DllImport(@"APIs\NVR\HCNetSDK.dll", EntryPoint = "NET_DVR_Login_V30", CharSet = CharSet.Ansi)]
        //public static extern string NET_DVR_Login_V30(string sDVRIP, ushort wDVRPort, string sUserName, string sPassword,lpDeviceInfo);
        /// <summary>
        /// 设置抓图模式
        /// </summary>
        /// <param name="dwCaptureMode">抓图模式 enum tagPDC_PARAM_KEY{  BMP_MODE    = 0,  JPEG_MODE   = 1}CAPTURE_MODE</param>
        /// <returns></returns>
        [DllImport(@"APIs\NVR\HCNetSDK.dll", EntryPoint = "NET_DVR_SetCapturePictureMode", CharSet = CharSet.Ansi)]
        public static extern bool NET_DVR_SetCapturePictureMode(UInt32 dwCaptureMode);
        /// <summary>
        /// 单帧数据捕获并保存成JPEG图。 
        /// </summary>
        /// <param name="lUserID">NET_DVR_Login或NET_DVR_Login_V30的返回值 </param>
        /// <param name="lChannel">通道号 </param>
        /// <param name="lpJpegPara">JPEG图像参数</param>
        /// <param name="sPicFileName">保存JPEG图的文件路径</param>
        /// <returns></returns>
        [DllImport(@"APIs\NVR\HCNetSDK.dll", EntryPoint = "NET_DVR_CaptureJPEGPicture", CharSet = CharSet.Ansi)]
        public static extern bool NET_DVR_CaptureJPEGPicture(ref UInt32 lUserID, ref UInt32 lChannel, ref NET_DVR_JPEGPARA lpJpegPara, ref string sPicFileName);
        /// <summary>
        /// 单帧数据捕获并保存成JPEG存放在指定的内存空间中。
        /// </summary>
        /// <param name="lUserID">[in] NET_DVR_Login或NET_DVR_Login_V30的返回值 </param>
        /// <param name="lChannel">[in] 通道号</param>
        /// <param name="lpJpegPara">[in] JPEG图像参数</param>
        /// <param name="sJpegPicBuffer">[in] 保存JPEG数据的缓冲区</param>
        /// <param name="dwPicSize">[in] 输入缓冲区大小</param>
        /// <param name="lpSizeReturned">[out] 返回图片数据的大小</param>
        /// <returns></returns>
        [DllImport(@"APIs\NVR\HCNetSDK.dll", EntryPoint = "NET_DVR_CaptureJPEGPicture_NEW", CharSet = CharSet.Ansi)]
        public static extern bool NET_DVR_CaptureJPEGPicture_NEW(ref UInt32 lUserID, ref UInt32 lChannel, ref NET_DVR_JPEGPARA lpJpegPara, ref string sJpegPicBuffer, ref UInt32 dwPicSize, out UInt32[] lpSizeReturned);

    }

}
